<?php
$sql = "SELECT * FROM facilidadearea ORDER BY fac_are_nome";
$res = sql($sql);
while($linha=  mysql_fetch_array($res)){
?>
<h4><?=$linha['fac_are_nome'];?></h4>
<ul class="nav nav-pills nav-stacked">
    <?php
    $sql1 = "SELECT * FROM facilidade WHERE are_id='{$linha['fac_are_id']}' AND sta_id='1'";
    $res1 = sql($sql1);
    while($linha1 = mysql_fetch_array($res1)){
        if ($linha1['fac_url'] != "") { $url = $linha1['fac_url']; } else { $url = $linha1['fac_site']; }
    ?>
    <li><a href="<?=$url;?>" target="_blank"><?=$linha1['fac_nome'];?></a></li>
    <?php } ?>
</ul>
<?php } ?>
